(function ($) {
	operModeSetup()
	function scoreTextTapped(){
		var textDom = this
		removeActive()
		var liDom = textDom.parentNode.parentNode
		currLiId = liDom.id
		liDom.classList.add('dhc-active')
		liDom.classList.add('text-active')
		opBoard.showDHCKeyboard();
		mui('#wrapper').scroll().reLayout();
		var index = parseInt(liDom.id)
		scrollToNewActiveScorLi(liDom);
		var score = paperData['SubItems'][index]['ItemScore']
		opBoard.updateDHCKeyboardUI(score);
	}
	
	function computeScore() {
		var items = paperData['SubItems']
		var realScore = 0;
		var errCount=0,corrCount=0;
		for(var i = 0; i < items.length; i++) {
			var itemDict = items[i];
			if(itemDict['HasChild'] == '1') {
				continue;
			}
			var itemScore = itemDict['ItemScore']
			if (itemScore == '') {
				continue
			}
			itemScore = itemScore.split('」')
			for (var j = 0; j < itemScore.length;j++) {
				var num = parseFloat(itemScore[j]);
				if (isNaN(num)) {
					continue
				}
				if (j == 0) {
					corrCount += num
				}else{
					errCount += num
				}
			}
		}
		var count = corrCount + errCount;
		if(count == 0) {
			realScore = '100%';
		} else {
			realScore = (100 * corrCount / count) + '%';
		}
		realScore = keepTwoDecimalPlaces(realScore); //--公共方法
		mui('#totalScore')[0].innerText = realScore;
		checkScore = realScore
	}
	function fitPopoverBlock(type,inputText,newScore){
		var activeLi = mui('#scroll li.dhc-active')[0];
		if(!activeLi) {
			hideScoringPopover()
			return;
		}
		var rowIndex = parseInt(activeLi.id)
		var itemDict =paperData['SubItems'][rowIndex];
		
		if (type == 'notFit') {
			activeLi.querySelector('.scoreText').innerText = inputText
			paperData['SubItems'][rowIndex]['ItemScore']=newScore
			choseNextScoreText()
			computeScore()
		}else if (type == 'add' ||type == 'del' ||type =='clear') {
			activeLi.querySelector('.scoreText').innerText = inputText
			paperData['SubItems'][rowIndex]['ItemScore']=newScore
			computeScore()
		}else if (type == 'remark') {
			activeLi.classList.remove('dhc-active')
			mui.trigger(activeLi.querySelector('input'),'tap')
		}else if (type == 'last') {//上一个
			choseLastScoreText()
		}else if (type == 'next') {//下一个
			choseNextScoreText()
		}else if (type == 'close') {//关闭
			hideScoringPopover();
			currLiId = ''
		}
	}
	function operModeSetup(){
		mui('#scroll .scoreText').each(function (index,element) {
			element.addEventListener('tap',scoreTextTapped)
		})
		if (!opBoard ) {
			opBoard = new mui.DHCFitBoard('scroll','',function(type,inputText,newScore) {
				fitPopoverBlock(type, inputText,newScore);
			});
			
			
			//opBoard.openDHCKeyboardDrag();
		}
	}
})(mui)